﻿@extends("admin.base.base")
@section("title")
<title>资讯列表</title>
<link href="{{ asset('css/admin/css/paginate.css') }}" rel="stylesheet">
@endsection
@section("content")
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 资讯管理 <span class="c-gray en">&gt;</span> 文章列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="text-c">
		<button onclick="removeIframe()" class="btn btn-primary radius">关闭选项卡</button>
		<form action="{{url('admin/sou')}}" method="post" style="display: inline-block">
			<span class="select-box inline">
				<select name="classify" class="select">
					<option value="0">所有分类</option>
					<option value="1">分类一</option>
					<option value="2">分类二</option>
				</select>
			 </span>
			<input type="text" name="keywords" id="" placeholder=" 文章名称" style="width:250px" class="input-text">
			{{csrf_field()}}
			<button name="" id="search" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜文章</button>
		</form>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> <a class="btn btn-primary radius" data-title="添加资讯" data-href="{{url('admin/article/create')}}" onclick="Hui_admin_tab(this)" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加资讯</a></span> <span class="r">共有数据：<strong>{{$item->total()}}</strong> 条</span> </div>
	<div class="mt-20">
		<table class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
			<thead>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="" value=""></th>
					<th width="30">ID</th>
					<th width="120">文章标题</th>
					<th width="80">文章分类</th>
					<th width="80">文章重要性</th>
					<th width="30">浏览次数</th>
					<th width="50">更新时间</th>
					<th width="60">操作</th>
				</tr>
			</thead>
			<tbody>
			@foreach($item as $items)
				<tr class="text-c">
					<td><input name="pid[]" type="checkbox" value="{{$items->id}}"></td>
					<td>{{$items->id}}</td>
					<td>{{$items->title}}</td>
					<td>{{$items->category->title}}</td>
					@if($items->top == 1)
						<td>普通</td>
					@elseif($items->top == 2)
						<td>置顶</td>
					@else
						<td>普通</td>
					@endif
					<td>{{$items->amount}}</td>
					<td>{{$items->updated_at}}</td>
					<td class="f-14 td-manage"> <a style="text-decoration:none" class="ml-5" onClick="article_edit('资讯编辑','{{url('admin/article/'.$items->id.'/edit')}}','{{$items->id}}')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a> <a style="text-decoration:none" class="ml-5" onClick="article_del(this,'{{$items->id}}')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
				</tr>
			@endforeach
			</tbody>
		</table>
		<div class="pages">
			{{ $item->links() }}
		</div>
	</div>
</div>
@endsection
@section("js")
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="{{asset('lib/My97DatePicker/4.8/WdatePicker.js')}}"></script>
<script type="text/javascript" src="{{asset('lib/datatables/1.10.0/jquery.dataTables.min.js')}}"></script>
<script type="text/javascript" src="{{asset('lib/laypage/1.2/laypage.js')}}"></script>
<script type="text/javascript">
$('.table-sort').dataTable({
	"aaSorting": [[ 1, "desc" ]],//默认第几个排序
	"bStateSave": true,//状态保存
	"pading":false,
	"aoColumnDefs": [
	  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
	  {"orderable":false,"aTargets":[0,7]}// 不参与排序的列
	]
});

/*资讯-添加*/
function article_add(title,url,w,h){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}
/*资讯-编辑*/
function article_edit(title,url,id,w,h){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}
/*资讯-删除*/
function article_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
            headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
			type: 'POST',
			method:'DELETE',
			url: '{{url('admin/article')}}'+'/'+id,
            data:{'_token':'{{csrf_token()}}'},
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}
/*资讯-批量删除*/
function datadel() {
	var checked = $("input[name = 'pid[]']");
	var items = [];
	for (var i = 0;i < checked.length; i++){
		if (checked[i].checked){
            items.push(checked[i].value);
		}
	}

    layer.confirm('您确定要删除我们吗？', {
        btn: ['确定', '取消'],
    }, function() {
        $.post("{{ url('admin/delete') }}", {
            "ids": items,"_token": "{{csrf_token()}}"
        }, function(result) {
            if (result.code ==0){
                layer.msg('删除成功', {icon: 1});
                setTimeout(function () {
                    window.location.reload();
                },1000)
            }else {
                layer.msg(result.msg)
            }
        });
    }, function() {
        layer.close(layer.index);
    });
}

/*资讯-搜索*/
function sou(title,url,w,h) {
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}


/*资讯-发布*/
function article_start(obj,id){
	layer.confirm('确认要发布吗？',function(index){
		$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="article_stop(this,id)" href="javascript:;" title="下架"><i class="Hui-iconfont">&#xe6de;</i></a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已发布</span>');
		$(obj).remove();
		layer.msg('已发布!',{icon: 6,time:1000});
	});
}
</script>
@endsection